package com.huihong.internship.system.Controller;


import com.huihong.internship.system.DTO.StudentPageQueryDTO;
import com.huihong.internship.system.DTO.TeacherScoreDTO;
import com.huihong.internship.system.Service.TeacherService;
import com.huihong.internship.system.VO.StudentDetailVO;
import com.huihong.internship.system.VO.InternshipMaterialItemVO;
import com.huihong.internship.system.result.PageResult;
import com.huihong.internship.system.result.Result;
import com.huihong.internship.system.annotation.JwtAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    public TeacherService teacherService;

    /**
     * 分页查询指导学生列表
     * @return
     */
    @RequestMapping("/students")
    @JwtAuth
    public Result<PageResult> getStudentInfo(StudentPageQueryDTO dto, Long userId){
        PageResult pageResult = teacherService.getStudentPage(userId, dto);
        return Result.success(pageResult);
    }

    /**
     * 查看学生实习详情
     * @param studentId 学生ID
     * @return 学生实习详情
     */
    @GetMapping("/student/{studentId}/detail")
    @JwtAuth
    public Result<StudentDetailVO> getStudentDetail(@PathVariable Long studentId){
        StudentDetailVO studentDetail = teacherService.getStudentDetail(studentId);
        return Result.success(studentDetail);
    }


    /**
     * 查看学生提交的材料
     * @param studentId 学生ID
     * @param materialType 材料类型（可选：1 - 周志，2 - 实习报告，3 - 最终成果）
     * @return 学生提交的材料列表
     */
    @GetMapping("/student/{studentId}/materials")
    @JwtAuth
    public Result<List<InternshipMaterialItemVO>> getStudentMaterials(
            @PathVariable Long studentId,
            @RequestParam(required = false) Integer materialType){
        List<InternshipMaterialItemVO> materials = teacherService.getStudentMaterials(studentId, materialType);
        return Result.success(materials);
    }


    /**
     * 给出材料反馈
     * @param materialId
     * @param teacherFeedback
     * @return
     */
    // TODO  功能未完善
    @PutMapping("/material/{materialId}/feedback")
    public Result updatefeedback(@PathVariable Long materialId,@RequestBody String teacherFeedback){
        teacherService.updateFeedback(materialId,teacherFeedback);
        return  Result.success();

    }

    /**
     * 成绩评定
     * @param studentId 学生ID
     * @param scoreDTO 成绩评定数据
     * @return
     */
    @PostMapping("/student/{studentId}/score")
    @JwtAuth
    public Result submitScore(@PathVariable Long studentId, @RequestBody TeacherScoreDTO scoreDTO){
        teacherService.submitScore(studentId, scoreDTO);
        return Result.success();
    }


}
